package hn.cch.quartz.job;

import hn.cch.quartz.QuartzJobFactory;
import hn.cch.quartz.QuartzJobManager;
import hn.cch.spring.SpringAnnotation;
import hn.cch.spring.dao.SpringDao;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.util.Map;


@Component
public class QuartzJob extends QuartzJobBean {

    private static final Logger logger = LoggerFactory.getLogger(QuartzJob.class);

    @Autowired
    private SpringDao springDao;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        Map<String, Object> map = springDao.selectMap();
        for (String key:map.keySet()) {
            logger.info(key + ":" + map.get(key));
        }
        QuartzJobManager quartzJobManager = SpringAnnotation.getBean(QuartzJobManager.class);
        quartzJobManager.rescheduleJob();
    }
}
